package com.resourcestore.action;

import java.text.ParseException;
import java.util.List;

import com.resourcestore.utils.CommonUtil;
import com.resourcestore.action.BaseAction;
import com.resourcestore.dao.TermDao;
import com.resourcestore.model.Announce;
import com.resourcestore.model.Term;
import com.resourcestore.utils.tag.Pagination;

public class TermAction extends BaseAction {
	
	
	private Term term;
	private List<Term> listTerm;
	private TermDao termDao = new TermDao();
	private Pagination pagination = new Pagination();
	

	/**
	 * 查询返回List
	 * 
	 * @throws ParseException
	 * 
	 */
	public String listTerm() {
		term = new Term();
		pagination.setTotal(termDao.queryTermNum(term));
		listTerm = termDao.selectTermPage(term,pagination);

		for (int i = 0; i < listTerm.size(); i++) {
			try {
				listTerm.get(i).setGmtCreatedString(
						CommonUtil.getSysTimeFormatString(listTerm.get(i)
								.getGmtCreated()));
				listTerm.get(i).setGmtModifiedString(
						CommonUtil.getSysTimeFormatString(listTerm.get(i)
								.getGmtModified()));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return "default";
	}
	
	/**
	 * 预插入一条数据
	  */		
	public String preInsertTerm(){
		
		return newpath("/Term/insertTerm.jsp");		
	}


	/**
	 * 插入一条数据
	 */
	public String insertTerm() {

		try {
			term.setGmtCreated(CommonUtil.getSysTimeFormatNum());
			term.setGmtModified(CommonUtil.getSysTimeFormatNum());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		termDao.insertTerm(term);
		return redirect(this.getUrl());	
	}
	


	/**
	 * 更新之前加载原信息
	 * 
	 */
	public String preUpdateTerm() {

		term = termDao.selectTermById(term);

		return newpath("/Term/updateTerm.jsp");
	}

	/**
	 * 更新信息
	 * 
	 */
	public String updateTerm() {

		try {
			//term.setGmtCreated(CommonUtil.getSysTimeFormatNum());
			term.setGmtModified(CommonUtil.getSysTimeFormatNum());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		termDao.updateTerm(term);
		return redirect(this.getUrl());
	}

	/**
	 * 删除信息
	 */
	public String deleteTerm() {
		termDao.deleteTerm(term);
		return redirect(this.getUrl());
	}


	/**
	 * 批量删除信息
	 */
	public String deleteMoreTerm(){
	
		termDao.deleteMoreTerm(term);
		return redirect(this.getUrl());
	}


	


	public Pagination getPagination() {
		return pagination;
	}








	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}








	public Term getTerm() {
		return term;
	}








	public void setTerm(Term term) {
		this.term = term;
	}








	public List<Term> getListTerm() {
		return listTerm;
	}








	public void setListTerm(List<Term> listTerm) {
		this.listTerm = listTerm;
	}






	


}
